package com.moli.iov.admin.service.impl;

import com.moli.iov.admin.model.vo.req.CommandVo;
import com.moli.iov.admin.service.ICommandFacadeService;
import com.moli.iov.down.model.dto.req.VehicleCommandDto;
import com.moli.iov.down.remote.IVehicleCommandRemoteService;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.util.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 命令业务
 * </p>
 *
 * @author zql
 * @since 2019/9/18 13:10
 */
@Slf4j
@Service
public class CommandFacadeServiceImpl implements ICommandFacadeService {

  @Reference(group = "${service.group}",check = false)
  private IVehicleCommandRemoteService vehicleCommandRemoteService;

  /**
   * 发送命令
   * @param vehicleCommandVo
   * @return
   */
  @Override
  public RestResponse sendCommand(CommandVo vehicleCommandVo){
    return vehicleCommandRemoteService.sendCommand(convert(vehicleCommandVo));
  }

  /**
   * 升级命令
   * @param vehicleCommandVo
   * @return
   */
  @Override
  public RestResponse sendUpgrade(CommandVo vehicleCommandVo) {
    return vehicleCommandRemoteService.sendUpgrade(convert(vehicleCommandVo));
  }

  /**
   * 转换成 VehicleCommandDto
   * @param vehicleCommandVo
   * @return
   */
  private VehicleCommandDto convert(CommandVo vehicleCommandVo){
    VehicleCommandDto vehicleCommandDto = new VehicleCommandDto();
    CommonUtils.copyProperties(vehicleCommandVo, vehicleCommandDto);
    return vehicleCommandDto;
  }


}
